home *** CD-ROM | disk | FTP | other *** search
- Path: mudskipper.cac.psu.edu!user
- From: fcusack@tdx.org (frank.)
- Newsgroups: comp.lang.c
- Subject: Re: simple code, argc, argv, strcmp()
- Date: Fri, 16 Feb 1996 08:46:05 -0400
- Organization: Psychic Enemies Network
- Message-ID: <fcusack-1602960846050001@mudskipper.cac.psu.edu>
- References: <11f7cc$17261a.3b3@daprez> <4g1vl1$rm2@maverick.tad.eds.com>
- NNTP-Posting-Host: mudskipper.cac.psu.edu
-
- In article <4g1vl1$rm2@maverick.tad.eds.com>, Ed McGuffey
- <fgae23@ods04.and.ifg.gmeds.com> wrote:
-
- > If you really want to use the !, try:
- >
- > if (!((strcmp(argv[1], "-d") || (strcmp(argv[1], "-e")))
- > Usage();
- >
- > since you want the ! to apply to the entire expression consisting of the
- > two compares. The code is more readable, however, to avoid negative logic
- > altogether and just say:
- >
- > if ((strcmp(argv[1], "-d") || (strcmp(argv[1], "-e"))
- > function();
- > else
- > Usage();
-
- Let's see what would happen if argv[1] == "-d"
-
- if ( <zero> || <non-zero> ) /* evaluates to true, OK */
-
- The same would happen for argv[1] == "-e".
-
- Let's see what happens if argv[1] == "-k"
-
- if ( <non-zero> || <short-circuit, not evaluated> ) /* evals to true, not OK */
-
- Oh well.
- ~Frank
- -- I am Pentium of Borg. Division is futile. You will be approximated. --
- -- If you build it, they will come --> http://www.tdx.org/~fcusack/ --
- -- PGP key fingerprint: 01 C0 C0 B9 CC 78 67 0F 3F 64 80 65 8B 0F F9 EA --
-